package cn.neusoft.controller;

import cn.neusoft.pojo.Loginuser;
import cn.neusoft.vo.ResultBean;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/login")
public class LoginController {
	//这里发送post请求
	@PostMapping("/in")
	public ResultBean login(HttpSession session, @RequestBody Loginuser loginuser) {
		System.out.println("--------LoginController------login------------");
		System.out.println(loginuser);
		//先进行登录校验
		if("admin".equals(loginuser.getName())&& "123456".equals(loginuser.getPassword())) {
			System.out.println("——————————————————————————————————————————————");
			//密码和账号正确，就要分配一个session
			System.out.println(session.getId());
			session.setAttribute("adminUser",loginuser);
			//在这里要不要进行将登录信息给传递过去
			return ResultBean.SUCCESS("admin");
		}
		return ResultBean.ERROR("登录信息错误");
	}
	@GetMapping("/out")     // get + /log/out
	public ResultBean logout(HttpSession session){
		session.removeAttribute("adminUser");
		return ResultBean.SUCCESS();
	}
}
